/* 业务逻辑 */
(function() {
    Path.on(["/__basename__.html", "/"], function() {
        App.set("$Cache.current_page", 1);
        //随机获取商品
        coAjax.get(appConfig.goods.list_random, {
            bus_id: busInfo._id,
            num: 15,
            page: 0
        }, function(result) {
            App.set("$Cache.main.random_goods", result.result);
        }, function() {
            console.log(arguments);
        });
    });

    // 获取分类树结构
    function _init_classify_tree() {
        coAjax.get(appConfig.bus_classify_tree, {
            bus_id: busInfo._id
        }, function(classify_tree) {
            App.set("$Cache.main.classify_tree", classify_tree.result);
            classify_tree.result.childs.forEach(function(classify, index) {
                coAjax.get(appConfig.bus_classify_all_child_goods_by_id + classify.classify._id, {
                    bus_id: busInfo._id
                }, function(classify_info) {
                    App.concat("$Cache.main.classify_list", [{
                        _id: classify.classify._id,
                        title: classify.classify.classify_name,
                        contents: classify_info.result
                    }]);
                    App.set("$Cache.main.loading_tags_completed", true);
                });
            });
        });
    };
    _init_classify_tree();

    // 获取店铺列表
    var remote_server_url = "http://121.40.18.23:1518/api/complex/ClientStoreMapFactory";

    function _init_store_list() {
        $.getJSON(remote_server_url, {
            page_size: 12
        }, function(store_list_result) {
            App.set("$Cache.main.store_list", store_list_result.contents);
        });
    };
    _init_store_list();


    // 搜索
    App.set('$Event.href', function() {
        alert("???x")
        if (App.get('$Cache.search_text')) {
            Path.jump("searchset.html?q=" + App.get('$Cache.search_text'))
        } else {
            alert('error', '请输入搜索关键词');
        }
    });

}());

/*交互*/
;
